﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Web.WebSockets;
using System.Net.WebSockets;
using System.Web;
using System.Threading;
using System.Threading.Tasks;
using System.Text;

using WSServer;

namespace iShangMai.Controllers
{
    public class SocketController : ApiController
    {
        public HttpResponseMessage Get()
        {
            if (HttpContext.Current.IsWebSocketRequest)
            {
                HttpContext.Current.AcceptWebSocketRequest(ProcessWS);
            }
            return new HttpResponseMessage(HttpStatusCode.SwitchingProtocols);
        }
        private async Task ProcessWS(AspNetWebSocketContext context)
        {
            WSSocket socket = WSSocket.New(context.WebSocket);

            await socket.RegisterSocketEvents();
        }
    }
}
